package com.wd.live;

import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.wd.live.view.fragment.mainfragment.ListFragment;
import com.wd.live.view.fragment.mainfragment.MyFragment;
import com.wd.live.view.fragment.mainfragment.NearFragment;
import com.wd.live.view.fragment.mainfragment.PiazzaFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
/*
*author：人类高质量男性项目组
* time:2021年9月26日
* 功能：主页面*/
public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    @BindView(R.id.vp_1)
    ViewPager vp1;
    @BindView(R.id.rg_piazza)
    RadioButton rgPiazza;
    @BindView(R.id.rg_nearfor)
    RadioButton rgNearfor;
    @BindView(R.id.rg_list)
    RadioButton rgList;
    @BindView(R.id.rg_my)
    RadioButton rgMy;
    @BindView(R.id.rg_1)
    RadioGroup rg1;
    @BindView(R.id.iv_start)
    ImageView ivStart;
    private List<Fragment> list = new ArrayList<>();
    private PiazzaFragment piazzaFragment=new PiazzaFragment();
    private NearFragment nearFragment=new NearFragment();
    private ListFragment listFragment=new ListFragment();
    private MyFragment myFragment=new MyFragment();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        Log.e(TAG, "onCreate:这是一行注释 ");
        list.add(piazzaFragment);
        list.add(nearFragment);
        list.add(listFragment);
        list.add(myFragment);
        Log.i(TAG, "onCreate: 哈哈哈哈哈哈");
        // TODO: 2021/9/26 主页面 ：RadioGroup与ViewPager联动
        rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.rg_piazza:{
                        vp1.setCurrentItem(0);
                        break;
                    }
                    case R.id.rg_nearfor:{
                        vp1.setCurrentItem(1);
                        break;
                    }
                    case R.id.rg_list:{
                        vp1.setCurrentItem(2);
                        break;
                    }
                    case R.id.rg_my:{
                        vp1.setCurrentItem(3);
                        break;
                    }
                }
            }
        });
        vp1.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return list.get(position);
            }

            @Override
            public int getCount() {
                return list.size();
            }
        });
        vp1.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                rg1.check(rg1.getChildAt(position).getId());
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
}